package models

import (
	. "kuaixinwen/database"
)
//表结构
type User struct {
	Id        int    `json:"id" form:"id"`
	Name string `json:"name" form:"name"`
	Age  string `json:"age" form:"age"`
}

func GetUserList(name, age string) (persons []User){

	//persons = make([]User, 0)
	//rows,err := DB.Query("select id,name,age from userinfo where name like '%?%' and age like '%?%'", name, age)
	//rows,err := DB.Query("select id,name,age from userinfo where name like '%"+name+"%' and age=?", age)
	rows,err := DB.Query("select id,name,age from userinfo")
	if err != nil {
		return nil
	}
	defer rows.Close()

	//数据添加到数据集中
	for rows.Next() {
		var person User
		rows.Scan(&person.Id, &person.Name, &person.Age)
		persons = append(persons, person)
	}
	if err = rows.Err(); err != nil {
		return nil
	}

	return persons
}
